#define _CRT_SECURE_NO_WARNINGS 1
#include<vector>
#include<queue>
using namespace std;
void solve(vector<vector<char>>& board) {
    for (int i = 0; i < board.size(); i++)
    {
        if (board[i][0] == 'O')
        {
            bfs(board, i, 0);
        }
        if (board[i][board[0].size() - 1] == 'O')
        {
            bfs(board, i, board[0].size() - 1);
        }
    }
    for (int i = 0; i < board[0].size(); i++)
    {
        if (board[0][i] == 'O')
        {
            bfs(board, 0, i);
        }
        if (board[board.size() - 1][i] == 'O')
        {
            bfs(board, board.size() - 1, i);
        }
    }


    for (int i = 0; i < board.size(); i++)
    {
        for (int j = 0; j < board[0].size(); j++)
        {
            if (board[i][j] == '.')
            {
                board[i][j] = 'O';
            }
            else
            {
                board[i][j] = 'X';
            }
        }
    }
}

void bfs(vector<vector<char>>& v, int a, int b) {
    int dx[4] = { 0,0,1,-1 };
    int dy[4] = { 1,-1,0,0 };
    queue<pair<int, int>> q;
    q.push({ a,b });
    v[a][b] = '.';
    while (q.size())
    {
        auto p = q.front();
        int m = p.first;
        int n = p.second;
        q.pop();
        for (int i = 0; i < 4; i++)
        {
            int x = m + dx[i];
            int y = n + dy[i];
            if (x >= 0 && y >= 0 && x < v.size() && y < v[0].size() && v[x][y] == 'O')
            {
                q.push({ x,y });
                v[x][y] = '.';
            }
        }
    }
}